{% extends 'base.html' %}
{% load mytags %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/base.js"></script>
    <script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.css"></script>
{% endblock %}
{% block content %}

    <script>
        window.onload=init;
        function init() {
            var box = document.getElementById("appconf");
            box.className="active";
            var box2 = document.getElementById("product");
            box2.className="active";
        }
    </script>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="{% url 'product_del' %}" method="post" id="product_form">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                    <div class="btn btn-group" style="padding-left: 0">
						 <a id="productadd" style="display: none;" class="btn btn-success" href="{% url 'product_add' %}">添加产品线</a>
                  </div>
                </div>

                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="productform">
                      <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="checkAll(this, 'item1');" />
                            </th>
                            <th>产品线名称</th>
                            <th>产品线描述</th>
                            <th>负责人姓名</th>
                            <th>负责人电话</th>
                            <th>操作</th>
                        </tr>
                      </thead>
                            <tbody>
                            {% for product in all_product %}
                                <tr class="even gradeX">
                                    <td><input type="checkbox" id="u_id" class="i-checks" value="{{ product.id }}" name="g_check" /></td>
                                    <td><a href="#"><li style="list-style-type:none" onclick="return popWin(this.value)" value="{{ product.id }}">{{ product.name }}</li></a> </td>
                                    <td>{{ product.description }} </td>
                                    <td>{{ product.owner.name }} </td>
                                    <td>{{ product.owner.phone }} </td>
                                    <td>
                                        <a id="productedit" style="display: block; float:left; margin: auto;" href="{% url "product_edit" product.id %}"><span class="btn btn-sm btn-info">编辑</span></a>
                                        <a id="productdel" onclick="return checkSubmit()" style="display: block; float:left; margin: auto;" href="{% url "product_del"%}?id={{ product.id }}"><span class="btn btn-sm btn-danger ">删除</span></a>
{#                                        onclick="return confirm('确认删除？')"#}
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                  </table>
                  <div class="btn-group">
						 <button id="productdel" style="display: none" class="btn btn-danger " onclick="return checkSubmit()">删除品线</button>
                  </div>
                </div>
            </div>
        </form>
    </section>

</div>
<script>
  $(function () {
    $('#productform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "bAutoWidth": false
    });
  });
</script>
<script>
function checkAll(sender, checkClass) {
    var checkItems = document.getElementsByTagName('input');
    for (var i = 0; i < checkItems.length; i++) {
        var checkItem = checkItems[i];
        if (checkItem.type === 'checkbox' && checkItem.className === 'item1') {
            checkItem.checked = sender.checked;
        }
    }
}
</script>
<script>
function checkSubmit() {
    if (!confirm("确定删除？")) {
        window.event.returnValue = false;
    }
}
</script>

<script>
function popWin(product_id){
  layer.open({
      type: 2,
      title: '项目列表',
      area: ['700px', '500px'],
      shadeClose: true, //点击遮罩关闭
      content: ['/appconf/productplist/' + product_id]
  });
}
</script>
{% endblock %}
